//
//  BaseNavigationController.swift
//  Community
//
//  Created by Vampire on 2019/7/18.
//  Copyright © 2019 ZKJ. All rights reserved.
//

import UIKit

class SWPTBaseNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        

        self.navigationBar.setBackgroundImage(UIImage.init(color: mainGreenColor), for: .default)
        self.navigationItem.hidesBackButton = true
        self.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
        self.navigationBar.shadowImage = UIImage()
        self.navigationBar.isTranslucent = false
        
    }
    
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            let back = UIButton(type: UIButton.ButtonType.custom)
            back.frame = CGRect(x: 0,y: 0 ,width: 44,height: 44)
            back.setImage(UIImage.init(named: "black_return")?.byTintColor(UIColor.white), for: UIControl.State.normal)
            back.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
            back.addTarget(self, action: #selector(popViewController(animated:)), for: UIControl.Event.touchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: back)
       
        }
        super.pushViewController(viewController, animated: animated)
        
        
        // 修改tabBra的frame
        let tabBarFrame = self.tabBarController?.tabBar.frame
        let newY = UIScreen.main.bounds.height - (tabBarFrame?.height ?? 0.0)
        let newFrame = CGRect(x: tabBarFrame?.origin.x ?? 0.0, y: newY, width: tabBarFrame?.width ?? 0.0, height: tabBarFrame?.height ?? 0.0)
        self.tabBarController?.tabBar.frame = newFrame
    }
    
    

}
